<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>员工管理</title>
	<#include "./comm/meta-base.ftl" />
	<#include "./comm/meta-easyui.ftl" />
	<#include "./comm/meta-comm.ftl" />
	<link href="${basePath}/static/css/privilege.css" rel="stylesheet" />
</head>
<body>
<div class="easyui-layout" fit="true" >
    
    <div data-options="region:'west'" style="width:300px;" >
    	<!--
        <ul id="org_tree" class="easyui-tree" data-options="
        	url:'${basePath}/company/company-tree-json',
        	method:'get',
        	animate:true,
        	lines:true,
        	onLoadSuccess:orgLoadSuccess,
        	onClick:orgClick
        "></ul>
        -->
        
        <table id="org_tree" class="easyui-treegrid"  border="0"  rownumbers="true" fitColumns="true" fit="true"
               data-options="
                   url: '${basePath}/company/company-tree-json',
                   method: 'get',
                   rownumbers: true,
                   idField: 'id',
                   lines: true,
                   onLoadSuccess:orgTreeSuccess,
	               onClickRow:orgTreeClickRow,
                   treeField: 'text'
               ">
           <thead>
           <tr>
                <th data-options="field:'text',width:300">公司组织树</th>
            </tr>
           </thead>
       </table>
        
        
    </div>
    
    <div data-options="region:'center'" >
    	<div id="datagrid_toolbar">
    		 <form id="search_form" class="search-form" role="form"   method="post" >
            	<div class="row">
                      <div class="form-group col-sm-4">
                        <label class="col-sm-4 fm-label">员工姓名</label>
                        <div class="col-sm-8 fm-control">
                            <input type="text" class="form-control" name="personName" />
                        </div>
                      </div>
                      
                      <div class="form-group col-sm-4">
                        <label class="col-sm-4 fm-label">登录名</label>
                        <div class="col-sm-8 fm-control">
                            <input type="text" class="form-control" name="loginName"  />
                        </div>
                      </div>
                      <div class="form-buttons col-sm-4" >
                      	<a href="javascript:submitForm()" class="btn btn-sm   btn-blue">
                            <i class="btn-label fa  fa-search "></i>查 询</a>
                        
                        <a href="javascript:resetForm('search_form')" class="btn btn-sm 
                        btn-default  margin-left-10 ">
                            <i class="btn-label fa  fa-reply "></i>重 置</a>
                    </div>
                 </div>
            </form>
    		
    	
    	
            <div class="buttons-preview" >
                <a class="btn btn-default  btn-sm" 
                	href="javascript:addStaff()"><i class="fa fa-plus"></i>新增员工</a>
                <a class="btn btn-primary btn-sm" 
                	href="javascript:modifyStaff()"><i class="fa fa-edit"></i>修改员工</a>
                <a class="btn btn-danger btn-sm" 
                	href="javascript:removeStaff()"><i class="fa fa-times"></i>删除</a>
            </div>
        </div>
    
        <table id="data_table" class="easyui-datagrid"  border="0"    pagination="true" pageSize='20'   rownumbers="true" fitColumns="true" fit="true"
	               data-options="
	                   url: '${basePath}/staff/staff-list-json/ROOT',
	                   method: 'get',
	                   rownumbers: true,
	                   idField: 'id',
	                   singleSelect: true,
	                   toolbar:'#datagrid_toolbar',
	                   onClickRow:staffTableClickRow
	               ">
	           <thead>
	           <tr>
	                <th data-options="field:'name',width:width(0.1)">员工姓名</th>
	                <th data-options="field:'loginName',width:width(0.1)">员工登录名</th>
	                <th data-options="field:'companyName',width:width(0.05)">公司</th>
	                <th data-options="field:'departmentName',width:width(0.05)">部门</th>
	                <th data-options="field:'isDefault',width:width(0.1)">是否默认</th>
	            </tr>
	           </thead>
	       </table>
        
        
    </div>
    
    <div data-options="region:'east'" style="width:300px;" >
    	<table id="tree_table" class="easyui-treegrid "  border="0"  rownumbers="true" fitColumns="true" fit="true"
	               data-options="
	               	   url:'${basePath}/staff/staff-privilege-tree-json/NONE',
	                   method: 'get',
	                   rownumbers: true,
	                   idField: 'id',
	                   lines: true,
	                   checkOnSelect:false,
	                   treeField: 'text'
	               ">
	           <thead>
	           <tr>
	                <th data-options="field:'text',width:250">权限树</th>
	                <!--
	                <th data-options="field:'operateJSON',width:width(0.3),formatter:operatePriFormatter">操作权限</th>
	                -->
	            </tr>
	           </thead>
	       </table>
    </div>
</div>

</body>
</html>
<style>
.tree .tree-folder:before, .tree .tree-item:before{content:inherit !important;position:static !important; display:inline; font-size:14px;}
.tree .tree-item, .tree .tree-folder{border:0px;}
.tree-file, .tree-folder-open, .tree-folder{font-size:14px;}

</style>
<script type="text/javascript">


function orgTreeClickRow(row){	
	//console.log(row);	
	var url="${basePath}/staff/staff-list-json/"+row.id;
	$.ajax({
		url: url,
		type: "POST",
		dataType:'json',
		success: function (data) {
			$("#data_table").datagrid('loadData',data);
		}
	});
	var tdata=[];
	$("#tree_table").treegrid('loadData',tdata);	
		
}
function orgTreeSuccess(){
	/**
	var row=$('#org_tree').datagrid('selectRow',0);
	var url="${basePath}/staff/staff-list-json/"+row.id;
	$.ajax({
		url: url,
		type: "POST",
		dataType:'json',
		success: function (data) {
			$("#data_table").datagrid('loadData',data);
		}
	});
	var tdata=[];
	$("#tree_table").treegrid('loadData',tdata);	
	**/
}



function removeStaff(){
	var row = $('#data_table').datagrid('getSelected');
	if(null!=row){
		var url="${basePath}/staff/staff-remove/"+row.staffId;
		bootbox.confirm("你确定要删除"+row.name+"?", function (result) {
        	if (result) {
            	$.post(url,{},function(data){
					window.location.reload();
				});
         	}
        });
		
		
	}else{
		Notify('请选择要删除的员工', 'top-right', '5000', 'danger', 'fa-bolt', true);
	}

}


function modifyStaff(){
	var row = $('#data_table').datagrid('getSelected');
	if(null!=row){
		var url="${basePath}/staff/staff-modifyin/"+row.staffId;
		MainTab.createTab("STAFFMODIFY","修改员工",url);
	}else{
		Notify('请选择要修改的员工', 'top-right', '5000', 'danger', 'fa-bolt', true);
	}
	
}

function addStaff(){
	//var node = $('#org_tree').tree('getSelected');
	var node = $('#org_tree').datagrid('getSelected');
	
	if(null!=node&&node.type=='DEPARTMENT'){
		var url="${basePath}/staff/staff-addin?departmentId="+node.id;
		//console.log(url);
		MainTab.createTab("STAFFADD","新增员工",url);
	}else{
		Notify('请选择部门!', 'top-right', '5000', 'danger', 'fa-bolt', true);
	}
}

function submitForm(){
	//var node = $('#org_tree').tree('getSelected');  
	var node = $('#org_tree').datagrid('getSelected');
	var orgId=node.id;
	$("#search_form").form('submit', {
		url : '${basePath}/staff/staff-list-json/'+orgId,
		success : function(data) {
			var obj = jQuery.parseJSON(data);  
			$("#data_table").datagrid('loadData',obj);
			var tdata=[];
			$("#tree_table").treegrid('loadData',tdata);
		}
	});
}

function operatePriFormatter(value,row,index){
	var html="";
	if(''!=value&&null!=value){
		var operateJSON = eval("(" + value + ")"); 
		for(var i=0;i<operateJSON.length;i++){
			var operateObj=operateJSON[i];
			html+="<div value='"+operateObj.operateId+"' class='operateDiv ' >"+operateObj.name+"</div>";
		}
	}
	return html;
}

function staffTableClickRow(index,row){
	var url="${basePath}/staff/staff-privilege-tree-json/"+row.staffId;
	$.ajax({
		url: url,
		type: "POST",
		dataType:'json',
		success: function (data) {
			$("#tree_table").treegrid('loadData',data);
		}
	});

}

function orgClick(node){
	var url="${basePath}/staff/staff-list-json/"+node.id;
	$.ajax({
		url: url,
		type: "POST",
		dataType:'json',
		success: function (data) {
			$("#data_table").datagrid('loadData',data);
		}
	});
	var tdata=[];
	$("#tree_table").treegrid('loadData',tdata);
}
function orgLoadSuccess(node,data){
	var tar=$("#org_tree").tree("find","ROOT");
	$("#org_tree").tree("select",tar.target);
	var url="${basePath}/staff/staff-list-json/"+tar.id;
	$.ajax({
		url: url,
		type: "POST",
		dataType:'json',
		success: function (data) {
			$("#data_table").datagrid('loadData',data);
		}
	});
}
</script>


